#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
typedef double db;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-')f=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') { x=(x<<1)+(x<<3)+ch-'0'; ch=getchar(); }
	return x*f;
}
const int MAXN=40;
int n,g[4][MAXN];
LL f[4][MAXN];
bool vis[4];
int main()
{
	n=read();
	for(int i=1;i<=6;++i)
	{
		char tmp[5];
		scanf("%s",tmp);
		int x=tmp[0]-'A'+1,y=tmp[1]-'A'+1;
		if(vis[x])continue;
		vis[x]=true;
		g[x][1]=y;
		f[x][1]=1;
	}
	for(int i=2;i<=n;++i)
		for(int j=1;j<=3;++j)
		{
			int y=g[j][i-1],k=6-y-j;
			f[j][i]=f[j][i-1]+1;
			if(k==g[y][i-1])
			{
				f[j][i]+=f[y][i-1];
				g[j][i]=k;
			}
			else
			{
				f[j][i]+=f[y][i-1]+1+f[j][i-1];
				g[j][i]=y;
			}
		}
	printf("%lld\n",f[1][n]);
	return 0;
}
